#!/bin/bash

function replace()
{
    sed -i '' "s#${2}#${3}#g" $1
}

function delete()
{
    sed -i '' "${2}d" $1
}

function deleteSE()
{
    sed -i '' "${2},${3}d" $1
}

#路径
path=/Users/zc/Desktop
#目录名
dir=drycms
#完整路径
full=${path}/${dir}
#是否商业版本
vip=1
#切换到指定目录、删除代码、克隆代码
cd ${path}
rm -rf ./${dir}
git clone https://gitee.com/xxfaxy/swoole_zephir.git ${dir}
#替换文件
cd ${dir}
replace ./docker-compose.yml registry.cn-beijing.aliyuncs.com/lingchuang/drycms drycms
replace ./local.sh registry.cn-beijing.aliyuncs.com/lingchuang/drycms drycms
deleteSE ./docker-compose.yml 13 21
deleteSE ./Dockerfile 7 8
deleteSE ./run-from.sh 3 7
replace ./code/src/Config/common/alipay.yaml 2019032563641524 请替换
replace ./code/src/Config/common/alipay.yaml "MIIEowIBAAKCAQEAo15XGJSqrTjomrmZxQOgcMDVep0CiNXJP+MPgOc8bx+dkSeTGty9sYcGufjA4RKxKNsawZlI7oEyJ0bFwftMuY8J8YYwxu/pxOepOgxX1ERVC8OiAfTz2s/GW3kw9uMpbZWpzWnIJ4KM3h69bkrG85jfWpWhk1waIfHNmi472/n+WTdskI20gxnyaXFznt617uJjhFQicEFWs+QHtcUJPKBiIbooJuPU8mYs1Encj3SPQ4Rk03JBbEvK3GXXX5WNFhodlre7QvCf9TVxV7XfX91wIH9CSUu4TgZRalJn8zP54iw6MdDbeIo5FCnPPBLf6DZgfA8FDUDCftAZq3tGSQIDAQABAoIBACFSIaOS1wkDvXWpe3KSncvBmQksMxMjv6t3LXdWMp5brXCoyLlG4q3t43JVCUoe3OF/ZwKruBNlaIxYRAefsPN7+EQ54YMB9gVCVuLPF67kzQ/cNBQAGSi9DjEkE9eXV6DRUNPjyn48g2zeijaPq+qNeKjqMg1zUKUxw4S5/12LWWTYlQ9t1vEfqhynk/SUWuVuI/A9nCIS0OShKCtQkqU+h5EGN88/7bcHBpWg5ZEgA5oLG5/0sJDo7r6a3qcd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+lRuy773um0kAYFkKyDt4pqPJ9JdfEiBCI9hPRp4LATvzs3uUqTMIAVAcY7ExvJ8rereMX0xqEMJFfm/y6C158i7SnzEnfPDrKYZNZElQyRgPZoRtEs8v3oPM3huprK2Tp+r/auxCy7pt85cbAXcAWKHur+DwlfYAzrQ8PT24bA9FlXi61TZAjeIYKHjD4LSZot3nZrUyUplqtWkRLnSVEFspt4f+gTE+LQGTM6P+C3D19IlX+9aGjXQ7g8LJOPr9J4JeloCx4j7JZ4mqwqq+jZvRTZqRsPWevHxzd1QIDAQAB" 请替换
replace ./code/src/Config/common/alipay.yaml https://api.chengshidian.cn/api/alipay/async2me 请替换
replace ./code/src/Config/common/code.yaml LTAIpuzTxOCDWBmL 请替换
replace ./code/src/Config/common/code.yaml zJkom2Fe3oC2oLsrpTckPMIgAwhYiw 请替换
replace ./code/src/Config/common/code.yaml 城食点 请替换
replace ./code/src/Config/common/code.yaml SMS_159621772 请替换
replace ./code/src/Config/common/encrypt.yaml 3c6e0b8a9c15224a 请替换
replace ./code/src/Config/common/encrypt.yaml f0b53b2da041fca4 请替换
replace ./code/src/Config/common/encrypt.yaml 9bef3793df43ea9d 请替换
replace ./code/src/Config/common/encrypt.yaml 8aef6e9996ff629b 请替换
replace ./code/src/Config/common/encrypt.yaml c38a79d66f03ffdc 请替换
replace ./code/src/Config/common/encrypt.yaml 97cacca3824685ad 请替换
replace ./code/src/Config/common/juhe.yaml 15a1052b77fa1dd5e9147255d5d273fc 请替换
replace ./code/src/Config/common/juhe.yaml fdb1f41cda055e175cbab1b1b2c3714e 请替换
replace ./code/src/Config/common/weixin.yaml wx7b935731c7a2f032 请替换
replace ./code/src/Config/common/weixin.yaml 1574830201 请替换
replace ./code/src/Config/common/weixin.yaml c5a581a8bf745d4da07405163ddae6bb 请替换
replace ./code/src/Config/common/weixin.yaml https://www.drycms.com 请替换
deleteSE ./code/src/Config/common/weixin.yaml 6 15
replace ./code/src/Config/local/oss.yaml zhouchun-temp 请替换
replace ./code/src/Config/local/oss.yaml LTAI4FmwcUeCtfkBRA3JiaDf 请替换
replace ./code/src/Config/local/oss.yaml YDD92nCCEOOb2yX0pPa15UfcC1BfJr 请替换
replace ./code/src/Config/local/oss.yaml 116.62.156.219:30000 请替换
replace ./code/src/Config/local/oss.yaml zhouchun-temp 请替换
deleteSE ./code/src/Config/local/oss.yaml 12 30
replace ./code/src/Config/local/sign.yaml gzlc2020168 请替换
replace ./code/src/Config/product/oss.yaml zhouchun-temp 请替换
replace ./code/src/Config/product/oss.yaml LTAI4FmwcUeCtfkBRA3JiaDf 请替换
replace ./code/src/Config/product/oss.yaml YDD92nCCEOOb2yX0pPa15UfcC1BfJr 请替换
replace ./code/src/Config/product/oss.yaml api.lingchuangkeji.net 请替换
deleteSE ./code/src/Config/product/oss.yaml 12 30
replace ./code/src/Config/product/sign.yaml gzlc2020168 请替换
#删除目录或文件
source ./publish/file/files.sh
count=${#files[@]}
for((i=0;i<count;i++))
    do
        rm -rf "${files[i]}"
    done
#非vip的处理
if [ $vip = 0 ];then
    rm -rf ./code/src/Application/Admin/Controller/File.php
    rm -rf ./code/src/Application/Api/Controller/File.php
    rm -rf ./code/src/Application/Admin/View/file
fi
#数据库的处理
source ./publish/file/sqls.sh
count=${#sqls[@]}
/usr/local/bin/mysqldump --column-statistics=0 -h'127.0.0.1' -P'3306' -u'root' -p'1234' drycms > /tmp/drycms.sql 2>/dev/null
/usr/local/bin/mysql -h'127.0.0.1' -P'3307' -u'root' -p'1234' drycms < /tmp/drycms.sql 2>/dev/null
for((i=0;i<count;i++))
    do
        /usr/local/bin/mysql -h'127.0.0.1' -P'3307' -u'root' -p'1234' -e"${sqls[i]}" drycms 2>/dev/null
    done
/usr/local/bin/mysqldump --column-statistics=0 -h'127.0.0.1' -P'3307' -u'root' -p'1234' drycms > ./drycms.sql 2>/dev/null
#文件的最后处理
rm -rf /tmp/layuiadmin
cp -r ./code/public/layuiadmin /tmp/
rm -rf ./code/public/layuiadmin && mkdir -p ./code/public/layuiadmin/modules
cp -r /tmp/layuiadmin/layui ./code/public/layuiadmin/
cp /tmp/layuiadmin/modules/cookies.js ./code/public/layuiadmin/modules/cookies.js
cp /tmp/layuiadmin/modules/dry.js ./code/public/layuiadmin/modules/dry.js
cp /tmp/layuiadmin/modules/file.js ./code/public/layuiadmin/modules/file.js
cp /tmp/layuiadmin/modules/icon.js ./code/public/layuiadmin/modules/icon.js
cp /tmp/layuiadmin/modules/layeditV2.js ./code/public/layuiadmin/modules/layeditV2.js
cp /tmp/layuiadmin/modules/uploadV2.js ./code/public/layuiadmin/modules/uploadV2.js
mv ./code/public/webComponents ./code/public/wc
rm -rf ./publish